/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.icanci.loopstack.damc.admin.biz.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.icanci.loopstack.damc.admin.biz.mapper.LogMapper;
import cn.icanci.loopstack.damc.admin.biz.service.LogService;
import cn.icanci.loopstack.damc.admin.common.model.base.LogVO;
import cn.icanci.loopstack.damc.admin.dal.common.PageList;
import cn.icanci.loopstack.damc.admin.dal.mongo.daointerface.LogDAO;
import cn.icanci.loopstack.damc.admin.dal.mongo.dateobject.LogDO;

/**
 * @author icanci
 * @since 1.0 Created in 2025/05/16 22:44
 */
@Service("logService")
public class LogServiceImpl implements LogService {
    @Resource
    private LogDAO    logDAO;
    @Resource
    private LogMapper logMapper;

    /**
     * 查询所有 T
     *
     * @return 返回所有T
     */
    @Override
    public List<LogVO> queryAll() {
        return logMapper.dos2vos(logDAO.queryAll());
    }

    /**
     * 保存或者更新一条信息
     *
     * @param logVO t
     */
    @Override
    public void save(LogVO logVO) {
        if (doInsert(logVO)) {
            LogDO insert = logMapper.vo2do(logVO);
            logDAO.insert(insert);
        } else {
            logDAO.update(logMapper.vo2do(logVO));
        }
    }

    /**
     * 根据id进行查询
     *
     * @param id id
     * @return 返回查询的结果
     */
    @Override
    public LogVO queryById(String id) {
        return logMapper.do2vo(logDAO.queryOneById(id));
    }

    /**
     * 分页查询
     *
     * @param logVO    T
     * @param pageNum  pageNum
     * @param pageSize pageSize
     * @return 返回分页查询结果
     */
    @Override
    public PageList<LogVO> queryPage(LogVO logVO, int pageNum, int pageSize) {
        PageList<LogDO> pageQuery = logDAO.pageQuery(logMapper.vo2do(logVO), pageNum, pageSize);
        return new PageList<>(logMapper.dos2vos(pageQuery.getData()), pageQuery.getPaginator());
    }
}
